auto();
var i = 0
var postpone = 2;
var height = device.height;
var width = device.width;
log("欢迎使用双十一自动领喵币脚本\n当前版本1.0\n来源：公众号【券儿吧】")
log("\n设备宽" + width + "\n" + "设备高" + height + "\n" + "手机型号" + device.model + "\n安卓版本" + device.release)
setScreenMetrics(width, height);

var speed = 1;

dialogs.alert("请确认无障碍和悬浮窗权限已开启，淘宝客户端为最新\n如果脚本不能用了，请关注公众号获取更新版本！！！");
menu: while (true) {
    var choose = dialogs.select("请根据你的手机性能(卡不卡)以及网速选择速度", "都挺好的,整个快速的", "一般吧,正常执行就好", "网速有点差,稍微慢点吧", "我手机很砖,整个最慢的吧");
    switch (choose) {
        case -1:
            log("请选择");
            continue menu;
        case 0:
            log("即将快速执行脚本");
            speed = 0.75;
            break menu;
        case 1:
            log("即将一般速度执行脚本");
            speed = 1;
            break menu;
        case 2:
            log("即将低速执行脚本");
            speed = 1.5;
            break menu;
        case 3:
            log("即将缓慢执行脚本");
            speed = 2;
            break menu;

        default:
            break;
    }
}

console.show();


postpone = speed * 1000;
launch("com.taobao.taobao");
sleep(5000);
/*
setScreenMetrics(device.width, device.height);
click(685,210);
*/
desc("搜索").findOne().click();
sleep(postpone);
id("searchEdit").findOne().setText("喵币");
sleep(postpone);
id("searchbtn").findOne().click();
sleep(postpone * 2);

text("赚喵币").findOne().click();
sleep(postpone * 3);

while (text("去浏览").exists()) {
    text("去浏览").findOne().click();
		sleep(1500);
		swipe(width / 2, height - 500, width / 2, 0, 500);
		sleep(2500);
		swipe(width / 2, height - 500, width / 2, 0, 500);
		sleep(10000);
		swipe(width / 2, height - 500, width / 2, 0, 500);
		sleep(8000);
		back();
		sleep(1600);
		i++;
		log("已完成第" + i + "次任务！")
		back();
		sleep(2 * postpone);
}

while (text("去完成").exists()) {
    text("去浏览").findOne().click();
		sleep(1500);
		swipe(width / 2, height - 500, width / 2, 0, 500);
		sleep(2500);
		swipe(width / 2, height - 500, width / 2, 0, 500);
		sleep(10000);
		swipe(width / 2, height - 500, width / 2, 0, 500);
		sleep(8000);
		back();
		sleep(1600);
		i++;
		log("已完成第" + i + "次任务！")
		back();
		sleep(2 * postpone);
}

log("浏览任务已经完成");
indexInParent(0).text("关闭").findOne().click();
sleep(postpone);
log("开始升级");
var merge = textContains("喂猫升级").findOne();
while (true) {
    merge.click();
    sleep(postpone);
    var receive = textContains("开心收下").findOnce();
    if (receive) {
        receive.click();
        //sleep(postpone);
    }
    var non_enough = text("哎哟，喵币不足啦").findOnce();
    if (non_enough) {
        indexInParent(3).text("关闭").findOne().click();
        break;
    }
    var decoration = text("领取成就勋章").findOnce();
    if (decoration) {
        indexInParent(4).text("关闭").findOne().click();
        break;
    }
}
log("执行完毕，开始拍猫");

var num = rawInput("输入拍猫次数（中途不可退，次数别太多）");
while (num--) {

    var cat=text("我的猫，点击撸猫").findOne();
    click(cat.bounds().centerX()+random(1,5)*5,
    cat.bounds().centerY()+random(1,5)*5);
    sleep(200);
}

log("任务貌似已经做完了\n如未完成，请重新运行\n欢迎关注公众号【券儿吧】了解更多内容");
launch("com.quanrba.tmall");
menu: while (true) {
		var choose = dialogs.select("淘宝还有个每日红包活动，要去领取吗？", "领取红包", "关注券儿吧", "算了退出");
		switch (choose) {
				case -1:
						log("请选择");
						continue menu;
				case 0:
						log("即将领取");
						setClip('￥7wU4c7yokQw￥');
			launch("com.taobao.taobao");
						break menu;
				case 1:
						log("即将打开微信，点击添加朋友并粘贴即可");
			setClip('券儿吧');
						launch("com.tencent.mm");
						break menu;
				case 3:
						log("即将退出脚本，感谢使用");
						break menu;
				default:
						break;
		}
}
exit();
